package leetcode.code0593;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
		return this.line2line(p1, p2, p3, p4) && this.line2line(p1, p3, p2, p4) && this.line2line(p1, p4, p2, p3)
				&& (this.line2line(p1, p2, p1, p3) || this.line2line(p1, p2, p1, p4) || this.line2line(p1, p3, p1, p4));
	}

	private boolean line2line(int[] p1, int[] p2, int[] p3, int[] p4) {
		long dist1 = line(p1, p2);
		long dist2 = line(p3, p4);
		return dist1 == 0 || dist2 == 0 ? false : dist1 == dist2;
	}

	private long line(int[] p1, int[] p2) {
		long dist1 = Math.abs(p1[0] - p2[0]);
		long dist2 = Math.abs(p1[1] - p2[1]);
		return dist1 * dist1 + dist2 * dist2;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(false, this.validSquare(HelpDebug.str2array3("[0,0]"), HelpDebug.str2array3("[5,0]"), HelpDebug.str2array3("[5,4]"),
				HelpDebug.str2array3("[0,4]")));
		HelpDebug.compare(true, this.validSquare(HelpDebug.str2array3("[0,0]"), HelpDebug.str2array3("[0,1]"), HelpDebug.str2array3("[1,1]"),
				HelpDebug.str2array3("[1,0]")));
		HelpDebug.compare(false, this.validSquare(HelpDebug.str2array3("[0,0]"), HelpDebug.str2array3("[1,1]"), HelpDebug.str2array3("[1,0]"),
				HelpDebug.str2array3("[0,12]")));
		HelpDebug.compare(true, this.validSquare(HelpDebug.str2array3("[1,0]"), HelpDebug.str2array3("[-1,0]"), HelpDebug.str2array3("[0,1]"),
				HelpDebug.str2array3("[0,-1]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
